using System;
using System.Threading.Tasks;
using System.Windows.Input;
using WpfAnimationDemo.Controls.WaferRobotV3;
using WPFTemplateLib.Mvvm;
using WPFTemplateLib.WpfHelpers;

namespace WpfAnimationDemo.ViewModels
{
    public class RobotV3ViewModel : ViewModelBase
    {
        #region 绑定

        public WaferRobotXAction WaferRobotXAction { get; set; }
        public WaferRobotZAction WaferRobotZAction { get; set; }
        public WaferRobotTAction WaferRobotTAction { get; set; }
		public WaferRobotRunAction WaferRobotRunAction { get; set; }

		public int WaferStatus { get; set; }

        #endregion

        #region 命令

        #region [命令] X轴动作
        private ICommand _XActionCmd;
        public ICommand XActionCmd => _XActionCmd ??= new RelayCommand<WaferRobotXAction>(ExecuteXActionCmd);
        private void ExecuteXActionCmd(WaferRobotXAction action)
        {
            WaferRobotXAction = action;
        }
        #endregion

        #region [命令] Z轴动作
        private ICommand _ZActionCmd;
        public ICommand ZActionCmd => _ZActionCmd ??= new RelayCommand<WaferRobotZAction>(ExecuteZActionCmd);
        private void ExecuteZActionCmd(WaferRobotZAction action)
        {
            WaferRobotZAction = action;
        }
        #endregion

        #region [命令] T轴动作
        private ICommand _TActionCmd;
        public ICommand TActionCmd => _TActionCmd ??= new RelayCommand<WaferRobotTAction>(ExecuteTActionCmd);
        private void ExecuteTActionCmd(WaferRobotTAction action)
        {
            WaferRobotTAction = action;
        }
		#endregion

		#region [命令] 运行动作
		private ICommand _RunActionCmd;
		public ICommand RunActionCmd => _RunActionCmd ??= new RelayCommand<WaferRobotRunAction>(ExecuteRunActionCmd);
		private void ExecuteRunActionCmd(WaferRobotRunAction action)
		{
			WaferRobotRunAction = action;
			if(WaferRobotRunAction == WaferRobotRunAction.Run_Extend)
			{
				WaferStatus = 1;
			}
			else
			{
				WaferStatus = 0;
			}
		}
		#endregion

		#region [命令] 自动
		private ICommand _AutoActionCmd;
        public ICommand AutoActionCmd => _AutoActionCmd ??= new RelayCommand<string>(ExecuteAutoActionCmd);
        private async Task ExecuteAutoActionCmd(string para)
        {
            WaferRobotTAction = WaferRobotTAction.T_CCW;
            await Task.Delay(1000);

            WaferRobotXAction = WaferRobotXAction.X_Forward;
            await Task.Delay(2000);

            WaferStatus = 1;
            await Task.Delay(200);

            WaferRobotXAction = WaferRobotXAction.X_Back;
            await Task.Delay(2000);

            WaferRobotZAction = WaferRobotZAction.Z_Up;
            await Task.Delay(1000);

            WaferRobotTAction = WaferRobotTAction.T_CW;
            await Task.Delay(1000);

            WaferRobotXAction = WaferRobotXAction.X_Forward;
            await Task.Delay(2000);

            WaferStatus = 0;
            await Task.Delay(200);

            WaferRobotXAction = WaferRobotXAction.X_Back;
            await Task.Delay(2000);

            WaferRobotTAction = WaferRobotTAction.T_Origin;
            await Task.Delay(1000);

            WaferRobotZAction = WaferRobotZAction.Z_Down;
        }
        #endregion

        #region [命令] 复原
        private ICommand _OriginActionCmd;
        public ICommand OriginActionCmd => _OriginActionCmd ??= new RelayCommand<string>(ExecuteOriginActionCmd);
        private void ExecuteOriginActionCmd(string para)
        {
            WaferRobotXAction = WaferRobotXAction.X_Origin;
            WaferRobotZAction = WaferRobotZAction.Z_Origin;
            WaferRobotTAction = WaferRobotTAction.T_Origin;
			WaferRobotRunAction = WaferRobotRunAction.Run_Origin;
            WaferStatus = 0;
        }
        #endregion

        #endregion

        #region 方法

        /// <inheritdoc />
        protected override void InitDataAfterConstruction()
        {
            Console.WriteLine($"机械手动画(V3)：使用用户控件方式");
        } 

        #endregion
    }
}
